package com.games.game.service;

import com.games.game.bean.Game;
import com.games.game.mapper.User_GameMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class User_Game_ServiceImp implements User_Game_Service{
    private User_GameMapper user_gameMapper;

    public User_Game_ServiceImp() {
        this.user_gameMapper = new User_GameMapper();
    }


    @Override
    public List<String> get_all_game(String u_name) {
        return user_gameMapper.get_all_game(u_name);
    }

    @Override
    public boolean has_game(String u_name, String g_name) {
        return user_gameMapper.has_game(u_name, g_name);
    }

    @Override
    public boolean purchase_game(String u_name, String g_name) {
        if (has_game(u_name, g_name)) {
            return false;
        }
        user_gameMapper.add_game(u_name, g_name);
        return true;
    }

    @Override
    public boolean refund(String u_name, String g_name) {
        if (!has_game(u_name, g_name)) {
            return false;
        }
        user_gameMapper.del_game(u_name, g_name);
        return true;
    }
}
